package chat;

import gui.CtfGui;
import gui.CtfLogin;

import java.awt.Color;
import java.awt.Graphics;
import java.util.LinkedList;

import client.Main;

public class CtfChat {
	public static final int MAX_NUM_MSGS = 5;
	static final int FONT_HEIGHT = 16;
	
	public static LinkedList<Integer> chatter = new LinkedList<Integer>();
	public static LinkedList<String> msgs = new LinkedList<String>(); 

	public static void addMsg(String s) {
		
		if ( msgs.size() < MAX_NUM_MSGS )
			msgs.add(s);
		else {
			msgs.pop();
			msgs.add(s);
		}
		if (CtfGui.getInstance() != null)
			CtfGui.getInstance().repaint();
	}
	
	public static void addMsg(int sender, String s) {
		if ( msgs.size() < MAX_NUM_MSGS ){
			msgs.add(s);
			chatter.add(sender);
	} else {
			msgs.pop();
			chatter.pop();
			msgs.add(s);
			chatter.add(sender);
		}
		if (CtfGui.getInstance() != null)
			CtfGui.getInstance().repaint();
	}
	
	public CtfChat() {
//		addMsg("Player1 : hellolo! start the game already!");
//		addMsg("Player2 : blah blah im crazy no no!");
//		addMsg("Player1 : This is crazy im loosing and winning! omgomg...");
//		addMsg("Player2 : kjansdkjansdkjansdkjansdkjansd ss");
//		addMsg("Player2 : noob");
	}
	
	public void render(Graphics g) {
		g.setColor( new Color( 0.0f ,0.0f,0.0f, 0.5f) );
		g.fillRect( 0, CtfGui.WINDOW_HEIGHT - 85 - (MAX_NUM_MSGS * FONT_HEIGHT),
				CtfGui.WINDOW_WIDTH, (MAX_NUM_MSGS * FONT_HEIGHT) + 10 );
		
		
		int startY = CtfGui.WINDOW_HEIGHT - 85 - (MAX_NUM_MSGS * FONT_HEIGHT);
		int i = 0;
		for ( String m : msgs ) {
			if ( ((chatter.get(i)+1 ) % 2)+1 == 1 ) 
				g.setColor( Color.pink );
			else
				g.setColor( Color.cyan );
			g.drawChars(m.toCharArray(), 0, m.length(), 15, startY+=16);
			i++;
		}
	}
}
